/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.report.saving;

import java.math.BigDecimal;
import java.util.List;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import src.domain.saving.Saving;
import src.services.saving.SavingModel;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
public class RptTransaksiTabunganDataSource implements JRDataSource{
    private int index = -1; 
    private List<Saving> savings;
    private SavingModel helper;

    public RptTransaksiTabunganDataSource() {
        helper = new SavingModel();    
        savings = helper.findAll(null);
    }
    
    
    
    @Override
    public boolean next() throws JRException {
        index++;
        //return (index < data.length);
        return (index < savings.size());
    }

    @Override
    public Object getFieldValue(JRField jrf) throws JRException {
         Object value = null;
         String fieldName = jrf.getName();
         /*
          * <field name="rekening" class="java.lang.String"/>
	<field name="nm_nasabah" class="java.lang.String"/>
	<field name="tgl_trans" class="java.util.Date"/>
	<field name="no_bukti" class="java.lang.String"/>
	<field name="kode_trans" class="java.lang.String"/>
	<field name="setoran" class="java.math.BigDecimal"/>
	<field name="penarikan" class="java.math.BigDecimal"/>
	<field name="user" class="java.lang.String"/>
	<field name="ket" class="java.lang.String"/>
	<field name="sum_setoran" class="java.math.BigDecimal"/>
	<field name="sum_penarikan" class="java.math.BigDecimal"/>
          */
         switch (fieldName) {
             case "rekening" : value = savings.get(index).getCustomer().getCif();break;
             case "nasabah" : value = savings.get(index).getCustomer().getCustomerName();break;
             case "tgl_trans" : value = savings.get(index).getOpenDate();break;
             case "no_bukti" : value = "<nomor bukti>";break;
             case "kode_trans" : value = "<Kode Trans>";break;
             case "user" : value = "<User>";break;
             case "ket" : value = "<Keterangan>";break;
             case "setoran" : value = new BigDecimal(0.00);break;
             case "penarikan" : value = new BigDecimal(0.00);break;
             case "sum_setoran" : value = new BigDecimal(0.00);break;
             case "sum_penarikan" : value = new BigDecimal(0.00);break;
         }
         return value;
    }
    
}
